<script>
	var url<?=$objectid?>;
	$(document).ready(function(){
	
		/*
		newData<?=$objectid?> = function (){
			$('#window<?=$objectid?>').dialog({
				title: 'Seleksi Calon Siswa',
				width: 750,
				height: $(window).height() * 0.98,
				closed: true,
				cache: false,
				href: base_url+'sd/psb/seleksi/add',
				modal: true,
				style:{background:'#dee5ff'}
			});
			 
			$('#window<?=$objectid?>').dialog('open');
			url<?=$objectid?> = base_url+'sd/psb/seleksi/save/add';
		}
		// end newData
		*/
		
		editData<?=$objectid?> = function (val){
			$('#window<?=$objectid?>').dialog({
				title: 'Edit Data Calon Siswa',
				width: 400,
				height: 270,
				closed: true,
				cache: false,
				href: base_url+'sd/psb/seleksi/edit/'+val,
				modal: true
			});
			
			$('#window<?=$objectid?>').dialog('open');  
			url<?=$objectid?> = base_url+'sd/psb/seleksi/save/edit';
		}
		//end editData
		
		// set status (penseleksian)
		seleksi<?=$objectid?> = function(id, stat){
			$.post( 
             base_url+'sd/psb/seleksi/set_status',
             { 'id': id, 'stat':stat },
             function(data) {
                //$('#stage').html(data);
                alert(data);
             }

          );
		}
		
		actionbutton<?=$objectid?> = function(value, row, index){
			var col="";
			if(row.status == 2 || row.status == 3){
				col += '<a href="#" onclick="editData<?=$objectid?>(\''+row.id+'\');" class="alink icon-edit"></a>';
			}
			return col;
		}
		
		// init grid
		$(function(){
			$('#dg<?=$objectid?>').datagrid({
				url:"<?=base_url()?>sd/psb/seleksi/grid",
				queryParams: {
					'id_psb' : $('#s_id_psb<?=$objectid?>').val(),
					'id_kelompok' : $('#s_id_kelompok<?=$objectid?>').val(),
				}
			});
		});
		
		/*
		// auto complite dan filter
		$('#s_id_psb<?=$objectid?>').change(function(){
			$('#s_id_kelompok<?=$objectid?>').load(base_url+'prosedur/get_gelombang_by_psb/'+$('#s_id_psb<?=$objectid?>').val());
		});
		*/
		
		filter<?=$objectid?> = function(){
			$('#dg<?=$objectid?>').datagrid('load',{
				'id_psb' : $('#s_id_psb<?=$objectid?>').val(),
				'id_kelompok' : $('#s_id_kelompok<?=$objectid?>').val(),
				'chk_1' : $('#s_chk_1<?=$objectid?>').is(':checked'),
				'chk_2' : $('#s_chk_2<?=$objectid?>').is(':checked'),
				'chk_3' : $('#s_chk_3<?=$objectid?>').is(':checked'),
			});
			//$('#dg').datagrid('enableFilter');
		}
		
		//# Tombol Bawah
		/*$(function(){
			var pager = $('#dg<?=$objectid?>').datagrid().datagrid('getPager');	// get the pager of datagrid
			pager.pagination({
				buttons:[
					
					{
						iconCls:'icon-add',
						text:'Seleksi',
						handler:function(){
							newData<?=$objectid?>();
						}
					}
					
				]
			});			
		});
		*/
		
		// formater
		set_status<?=$objectid?> = function(value, row, index){
			switch(value){
				case '2': return 'Lulus'; break;
				case '3': return 'Tidak Lulus'; break;
				case '1':
						var out="&nbsp;&nbsp;&nbsp;";
						out += '<label style="color:#00F"><input type="radio" name="radio'+index+'" value="2" onclick="javascript:seleksi<?=$objectid?>(\''+row.id+'\', this.value)" />&nbsp;Lulus</label>';
						out += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
						out += '<label style="color:#F00"><input type="radio" name="radio'+index+'" value="3" onclick="javascript:seleksi<?=$objectid?>(\''+row.id+'\', this.value)" />&nbsp;Tidak Lulus</label>';
						return out;
					break;
			}
		}
		
		
		
	});
</script>
<table id="dg<?=$objectid?>" title="Seleksi Calon Siswa : <?=$this->mdl_proses_penerimaan->get_title_penerimaan()?>, <?=$this->mdl_kelompok_penerimaan->get_title_kelompok()?> Tahun <?=$this->mdl_proses_penerimaan->get_title_tahun()?>" data-options="
			rownumbers:true,
			singleSelect:true,
			autoRowHeight:false,
			pagination:true,
			pageSize:50,
			pageList:[50, 100, 200, 300, 500],
			fit:true,
			toolbar:'#toolbar<?=$objectid?>',
			rowStyler: function(index,row){
				if (row.status == 1){
					return 'background-color:#FFF;color:#000;';
				}else if (row.status == 2){
					return 'background-color:#eaffe6;color:#000;';
				}else if(row.status == 3){
					return 'background-color:#fff6e6;color:#000;';
				}
			},
			onLoadSuccess: function(data){
				ShowGridMessage(this, 'Tidak Terdapat Data');
			},
			">
	<thead data-options="frozen:true">
		<tr>
			<th field="action" align="center" formatter="actionbutton<?=$objectid?>" width="50">Aksi</th>
		</tr>
	</thead>
	<thead>
		<tr>
			<th field="id" width="100" hidden="true"></th>
			<th field="no_pendaftaran" width="130">No. Pendaftaran</th>
			<th field="nama" width="150">Nama Calon</th>
			<th field="jk" width="40">JK</th>
			<th field="tgl_lahir" width="80">Tgl Lahir</th>
			<th field="uang_sumbangan" width="90" align="right">Sumbangan</th>
			<th field="status" width="200" formatter="set_status<?=$objectid?>">Status</th>
		</tr>
	</thead>
</table>

<div id="toolbar<?=$objectid?>" style="padding:0px;height:auto">
	<div class="fsearch">
		<div>
			<table width="100%" border="0" cellpadding="3" cellspacing="3">
				 <tr height="30px">
					<td width="50px">Status</td>
					<td>: 
						<label style="font-weight:normal;border:solid 1px #C2C2C2;background-color:#FFFFFF;margin:auto 5px;width:auto;"><input id="s_chk_1<?=$objectid?>" type="checkbox" checked="checked" /> Belum Seleksi&nbsp;&nbsp;&nbsp;</label>
						<label style="font-weight:normal;border:solid 1px #C2C2C2;background-color:#eaffe6;margin:auto 5px;width:auto;"><input id="s_chk_2<?=$objectid?>" type="checkbox" /> Lulus&nbsp;&nbsp;&nbsp;</label>
						<label style="font-weight:normal;border:solid 1px #C2C2C2;background-color:#fff6e6;margin:auto 5px;width:auto;"><input id="s_chk_3<?=$objectid?>" type="checkbox" /> Tidak Lulus&nbsp;&nbsp;&nbsp;</label>
					</td>
				  </tr>
				  
			  <tr style="display:none;">
				<td width="150px">Proses penerimaan</td>
				<td>: 
					<select name="s_id_psb" id="s_id_psb<?=$objectid?>" style="width:230px;">
						<?=$this->mdl_prosedur->option_proses_penerimaan();?>
					</select>
				</td>
			  </tr>
			  <tr style="display:none;">
				<td>Gelombang</td>
				<td>: 
					<select name="s_id_kelompok" id="s_id_kelompok<?=$objectid?>" style="width:230px;">
						<?=$this->mdl_prosedur->option_kelompok_penerimaan()?>
					</select>
				</td>
			  </tr>
			  <tr>
				<td>&nbsp;</td>				
				<td>&nbsp;&nbsp;<a href="#" onclick="filter<?=$objectid?>()" class="easyui-linkbutton" iconCls="icon-search" style="width:100px;">Filter</a></td>
			  </tr>
			</table>
		</div>
	</div>
</div>

<!-- AREA untuk Form Add >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>  -->
<div id="window<?=$objectid?>" class="easyui-dialog" style="width:400px;height:150px;" data-options="
		closed:true,
		minimizable:false,
		collapsible:false,
		maximizable:true,
		buttons:'#winbutton<?=$objectid?>',
		onResize:function(){
			$(this).window('center');
		}">
</div>
<div id="winbutton<?=$objectid?>">
	<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="save_data_seleksi<?=$objectid?>()">Save</a>
	<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#window<?=$objectid?>').dialog('close')">Cancel</a>
</div>